﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDW;
using DDW.Collections;
using AFSharedLibrary;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using UIDesigner.ControlProviders.Bases;
using UIDesigner.FieldHandlers.Bases;

namespace UIDesigner.FieldHandlers
{
    [FieldHandler(30.5f, null, typeof(bool), typeof(StringBuilder))]
    public class BooleanHandler : BaseFieldHandler
    {
        public BooleanHandler(AFDesignerHost objHost) : base(objHost)
        {
        }

        public new static Control AddControls(string strOption, IComponent ctrlParent, BaseNode objBase, bool bDefault, bool bPreview, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics, AFDesignerHost objHost)
        {
			 return BaseFieldHandler.AddControls(strOption, ctrlParent, objBase, bDefault, bPreview, nTabIndex, rgLocationRects, rgMnemonics, objHost);
        }

        public new static Control AddControls(string strOption, TableLayoutPanel ctrlParent, BaseNode objBase, bool bDefault, bool bPreview, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics, AFDesignerHost objHost)
        {
            return BaseFieldHandler.AddControls(strOption, ctrlParent, objBase, bDefault, bPreview, nTabIndex, rgTableLayoutPanelCellPositions, rgMnemonics, objHost);
        }

        public static void AddControlOptions(IComponent ctrlParent, BaseNode objBase, List<string> rgOptions)
        {
            if (ctrlParent is DataGrid)
            {
                //BooleanHandler		Checkbox 	CustomImageButton	

                if (HasSetter(objBase))
                {
                    rgOptions.Add(GridColumnOptions.CheckBoxColumn);
                }

                rgOptions.Add(GridColumnOptions.CustomImageButtonColumn);
                rgOptions.Add(GridColumnOptions.CustomDropdownControlColumn);

                DisplayableFieldHandler.AddControlOptions(ctrlParent, objBase, rgOptions);
            }
            else if (ctrlParent is ListView)
            {
                if (HasSetter(objBase))
                {
                    rgOptions.Add(ListViewColumnOptions.CheckBoxColumn);
                }

                rgOptions.Add(ListViewColumnOptions.CustomImageButtonColumn);
                rgOptions.Add(ListViewColumnOptions.CustomDropdownControlColumn);
                DisplayableFieldHandler.AddControlOptions(ctrlParent, objBase, rgOptions);
            }
            else
            {
                if (HasSetter(objBase))
                {
                    rgOptions.Add(ContainerControlOptions.CheckBox);
                    rgOptions.Add(ContainerControlOptions.ToggleButton);
                }

                DisplayableFieldHandler.AddControlOptions(ctrlParent, objBase, rgOptions);
            }
        }

		public override List<string> GetControlOptions(IComponent ctrlParent, BaseNode objBase)
        {
            //BooleanHandler		Checkbox 	ToggleButton							

            List<string> rgOptions = new List<string>();

            AddControlOptions(ctrlParent, objBase, rgOptions);

            return rgOptions;
        }

        public override bool SupportsParent(IComponent ctrlParent)
        {
            if (ctrlParent is DataGrid || ctrlParent is ListView)
            {
                return true;
            }
            else
            {
                return true;
            }

            return false;
        }

        public override Control AddDefaultControls(IComponent ctrlParent, BaseNode objBase, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics)
        {
            return AddControls(GetControlOptions(ctrlParent, objBase)[0], ctrlParent, objBase, true, false, nTabIndex, rgLocationRects, rgMnemonics, m_objHost);
        }

        public override Control AddControls(string strOption, IComponent ctrlParent, BaseNode objBase, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics)
        {
            return AddControls(strOption, ctrlParent, objBase, false, false, nTabIndex, rgLocationRects, rgMnemonics, m_objHost);
        }

        public override Control AddPreviewDefaultControls(IComponent ctrlParent, BaseNode objBase, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics)
        {
            return AddControls(GetControlOptions(ctrlParent, objBase)[0], ctrlParent, objBase, true, true, nTabIndex, rgLocationRects, rgMnemonics, m_objHost);
        }

        public override Control AddPreviewControls(string strOption, IComponent ctrlParent, BaseNode objBase, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics)
        {
            return AddControls(strOption, ctrlParent, objBase, false, true, nTabIndex, rgLocationRects, rgMnemonics, m_objHost);
        }

        public override Control AddDefaultControls(TableLayoutPanel ctrlParent, BaseNode objBase, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics)
        {
            return AddControls(GetControlOptions(ctrlParent, objBase)[0], ctrlParent, objBase, true, false, nTabIndex, rgTableLayoutPanelCellPositions, rgMnemonics, m_objHost);
        }

        public override Control AddControls(string strOption, TableLayoutPanel ctrlParent, BaseNode objBase, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics)
        {
            return AddControls(strOption, ctrlParent, objBase, false, false, nTabIndex, rgTableLayoutPanelCellPositions, rgMnemonics, m_objHost);
        }

        public override Control AddPreviewDefaultControls(TableLayoutPanel ctrlParent, BaseNode objBase, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics)
        {
            return AddControls(GetControlOptions(ctrlParent, objBase)[0], ctrlParent, objBase, true, true, nTabIndex, rgTableLayoutPanelCellPositions, rgMnemonics, m_objHost);
        }

        public override Control AddPreviewControls(string strOption, TableLayoutPanel ctrlParent, BaseNode objBase, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics)
        {
            return AddControls(strOption, ctrlParent, objBase, false, true, nTabIndex, rgTableLayoutPanelCellPositions, rgMnemonics, m_objHost);
        }
    }
}
